package org.ilovecode.screen
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.ilovecode.buttons.TextFloorButton;
	import org.ilovecode.mvc.View;
	
	public class FloorScreen extends Screen
	{
		protected var _floorButtons:Array;
		
		public function FloorScreen(type:String="", group:String="", name:String="")
		{
			super(type, group, name);
		}
		
		override protected function construct():void
		{
			// TODO Auto Generated method stub
			super.construct();
			
			_floorButtons = new Array();
		}
		
		override protected function addListeners():void
		{
			super.addListeners();
			
			for each (var button:TextFloorButton in _floorButtons) 
			{
				button.addEventListener(MouseEvent.CLICK, floorButton_Click);
				button.addEventListener(MouseEvent.MOUSE_OVER, floorButton_MouseOver);
				button.addEventListener(MouseEvent.MOUSE_OUT, floorButton_MouseOut);
			}
			
		}
		
		override protected function removeListeners():void
		{
			super.removeListeners();
			
			for each (var button:TextFloorButton in _floorButtons) 
			{
				button.removeEventListener(MouseEvent.CLICK, floorButton_Click);
				button.removeEventListener(MouseEvent.MOUSE_OVER, floorButton_MouseOver);
				button.removeEventListener(MouseEvent.MOUSE_OUT, floorButton_MouseOut);
			}
		}
		
		override protected function update(event:Event):void
		{
			// TODO Auto Generated method stub
			super.update(event);
		}
		
		protected function initTextFloorButton(floorNumber:int):void
		{
			var buttonName:String = "floor" + ((floorNumber >= 0) ? "" : "Minus") + Math.abs(floorNumber)  + "Button";
			var refMC:MovieClip = MovieClip(this.getChildByName(buttonName + "Ref"));
			var tfb:TextFloorButton = new TextFloorButton(floorNumber);
			tfb.x = refMC.x;
			tfb.y = refMC.y;
			this.addChild(tfb);
			_floorButtons.push(tfb);
			
		}
		
		protected function floorButton_Click(event:MouseEvent):void {
			showFloor(TextFloorButton(event.currentTarget).id);
		}
		
		protected function floorButton_MouseOver(event:MouseEvent):void {}
		
		protected function floorButton_MouseOut(event:MouseEvent):void {}
		
		public function showFloor(floorNumber:int):void {
			//Implement in child method
		}
	}
}